#include <cstdio>
#include <vector>
using namespace std;

vector<vector<int> > ST; // sparse table; ST[logN][N]

vector<int> logCache; // precalculated floor(log2(N)) for all numbers [0, 1, ... N]

vector<int> A; // array of numbers

int N; // amount of number in array A

void fillLogCache()
{
	logCache.reserve(N+1);
	logCache.push_back(-999); // log(0) is not defined

	int nextPowerOf2 = 2;
	int currentLogValue = 0;

	for (int i = 1; i <= N; ++i)
	{
		if (i == nextPowerOf2)
		{
			++currentLogValue;
			nextPowerOf2 <<= 1;
		}

		logCache.push_back(currentLogValue);
	}
}

void preprocess()
 {
	int logN = logCache[N]; // this is the max subrange length to store preprocessed valued in the sparse table

	ST.resize(logN+1);                   // allocate
	for (int i = 0; i < ST.size(); ++i)  //  memory
		ST[i].resize(N - (1 << i) + 1);  //   for the sparse table

	for (int i = 0; i < ST[0].size(); ++i)
		ST[0][i] = i;

	for (int j = 1; j <= logN; ++j)
	{
		for (int i = 0; i < ST[j].size(); ++i)
			ST[j][i] = A[ST[j-1][i]] > A[ST[j-1][i + (1<<(j-1))]] ? ST[j-1][i] : ST[j-1][i + (1<<(j-1))];
	}
}

// Returns index of minimum element in A
int RMQ(int i, int j) // inclusive [i,j].
{
	int k = j - i + 1; // range length

	int logK = logCache[k];

	return A[ST[logK][i]] > A[ST[logK][j + 1 - (1 << logK)]] ? ST[logK][i] : ST[logK][j + 1 - (1 << logK)];
}


int main()
{
	scanf("%d", &N);
	
	A.reserve(N);
	for (int i = 0; i < N; ++i)
	{
		int a;
		scanf("%d", &a);
		A.push_back(a);
	}

	fillLogCache();
	preprocess();

	int K; // queries
	scanf("%d", &K);
	while (K-->0)
	{
		int i, j;
		scanf("%d%d", &i, &j);
		int index = RMQ(i-1, j-1);
		printf("%d %d\n", A[index], index + 1);
	}
}